package edu.univercidade.tcc.sap.server;

import java.util.Properties;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class SAPServiceServlet extends RemoteServiceServlet {
	private static final long serialVersionUID = -1871590125755161781L;
	InitialContext initialContext;

	public SAPServiceServlet() throws NamingException {
		super();
		initialContextSetup();
	}

	public SAPServiceServlet(Object delegate) throws NamingException {
		super(delegate);
		initialContextSetup();
	}

	private void initialContextSetup() throws NamingException {
		Properties properties = new Properties();
		properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,
				"org.apache.openejb.client.LocalInitialContextFactory");
		initialContext = new InitialContext(properties);
	}
	
	@SuppressWarnings("unchecked")
	final <T> T ejbFind(Class<T> ejbInterface) throws NamingException {
		return  (T) initialContext.lookup(ejbInterface.getSimpleName());
	}
}